package elevatronic.view;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

public class MPanel  extends JPanel{
	private static final long serialVersionUID = 1351260669046871694L;
	

	
	
	//image of the left panel
	private ImageView imagePanel;
	public ImageView getImagePanel() {
		return imagePanel;
	}
	public void setImagePanel(ImageView imagePanel) {
		this.imagePanel = imagePanel;
	}
	
	//List of images
	public List<ImageView> getImages() {
		List<ImageView> retour= new ArrayList<ImageView>();
		retour.add(getImagePanel());
		return retour;
	}
	
	
	public MPanel(int wdth,int hght){
		setSize(wdth,hght);
		setVisible(true);
	    setLayout(null);
	    setOpaque(false);
	}

	//iteration of the left panel
	public void update(int step){
		//launch paintComponent(Graphics g)  
		this.repaint();
	}
	
	
	//this method draw and refresh all pictures
	public void paintComponent(Graphics g)  
	{
		super.paintComponent(g);
		if (getImages()!=null){
			for(ImageView image:getImages()){
				if (image!=null){
					if (image.isVisible()){
						g.drawImage(image.getImage(),image.getPosX(),image.getPosY(),image.getWdth(),image.getHght(),null);
					}
				}
			}
		}
	}
}
